import com.pbking.util.eventHandling.*;
/**
 * This class broadcasts global events such as "onEnterFrame", "onStageResize" and mouse events
 * @author Jason Crist
 */
class com.pbking.util.eventHandling.GlobalEventBroadcaster extends EventBroadcaster {
	
	// VARIABLES //////////
	
	private static var instance:GlobalEventBroadcaster;
	private var myRef:MovieClip;
	
	// CONSTRUCTION //////////
	
	public static function getInstance():GlobalEventBroadcaster{
		if(instance == null)instance = new GlobalEventBroadcaster();
		return instance;
	}
	
	private function GlobalEventBroadcaster(){
		
		this.myRef = _root.createEmptyMovieClip("__GlobalEventBroadcaster", 9875);
		this.myRef.__classRef = this;

		// onEnterFrame
		this.myRef.onEnterFrame = function(){
			this.__classRef.onEnterFrame();
		};
		
		// onStage*
		Stage.addListener(this);
		
		// onMouse*
		Mouse.addListener(this);

	}
		
	// PRIVATE LISTENING FUNCTIONS //////////
	
	private function onEnterFrame(){
		dispatch(new Event("onEnterFrame"));
	}
	
	private function onMouseMove(){
		dispatch(new Event("onMouseMove", {x:_root._xmouse, y:_root._ymouse}));
	}
	
	private function onMouseDown(){
		dispatch(new Event("onMouseDown", null, {x:_root._xmouse, y:_root._ymouse}));
	}
	
	private function onMouseUp(){
		dispatch(new Event("onMouseUp", null, {x:_root._xmouse, y:_root._ymouse}));
	}
	
	private function onMouseWheel(){
		dispatch(new Event("onMouseWheel"));
	}
	
	private function onResize(){
		dispatch(new Event("onStageResize"));
	}

}